package com.insideClass.event;

/**
 * @author 13699
 */
public class GreenHouseControls extends Controller {
    private boolean light = false;
    public class LightOn extends Event{

        protected LightOn(long eventTime, long delayTime) {
            super(eventTime, delayTime);
        }

        @Override
        public void action() {
            light=true;
        }

        @Override
        public String toString() {
            return "Light is on";
        }
    }
    public class LightOff extends Event{

        protected LightOff(long eventTime, long delayTime) {
            super(eventTime, delayTime);
        }

        @Override
        public void action() {
            light=false;
        }

        @Override
        public String toString() {
            return "light is off";
        }
    }
    private boolean water=false;
    public class WaterOn extends Event{

        protected WaterOn(long eventTime, long delayTime) {
            super(eventTime, delayTime);
        }

        @Override
        public void action() {
            water=true;
        }

        @Override
        public String toString() {
            return "Greenhouse water is on";
        }
    }
    public class WaterOff extends Event{

        protected WaterOff(long eventTime, long delayTime) {
            super(eventTime, delayTime);
        }

        @Override
        public void action() {
            water=false;
        }

        @Override
        public String toString() {
            return "Greengouse water is off";
        }
    }
    private String thermostat="Day";
    public class ThermostatNight extends Event{

        protected ThermostatNight(long eventTime, long delayTime) {
            super(eventTime, delayTime);
        }

        @Override
        public void action() {
            thermostat="Night";
        }

        @Override
        public String toString() {
            return "Thermostat on night setting";
        }
    }
    public class ThermostatDay extends Event{

        protected ThermostatDay(long eventTime, long delayTime) {
            super(eventTime, delayTime);
        }

        @Override
        public void action() {
            thermostat="Day";
        }

        @Override
        public String toString() {
            return "Thermostat on day setting";
        }
    }
    public class Bell extends Event{

        public Bell(long eventTime, long delayTime) {
            super(eventTime, delayTime);
        }
        @Override
        public void action() {
            addEvent(new Bell(eventTime,delayTime));
        }

        @Override
        public String toString() {
            return "Bing";
        }
    }
    public class Restart extends Event{

        private Event[] eventlist;

        protected Restart(long eventTime, long delayTime,Event[] eventlist) {
            super(eventTime, delayTime);
            this.eventlist=eventlist;
            /*

            for(元素类型t 元素变量x : 遍历对象obj){
                引用了x的java语句;
                }
             */
            for (Event e: eventlist) {
                addEvent(e);
            }
        }
        @Override
        public void action() {
            for (Event e:eventlist) {
                e.start();
                addEvent(e);
            }
            start();
            addEvent(this);
        }

        @Override
        public String toString() {
            return "Restarting system";
        }
    }
    public static class Terminate extends Event{

        protected Terminate(long eventTime, long delayTime) {
            super(eventTime, delayTime);
        }



        @Override
        public void action() {
            System.exit(0);
        }

        @Override
        public String toString() {
            return "Terminating";
        }
    }
}
